/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况, config观测数据, config梯子, tail观测,} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover, ItemConclusion} from "../../mobilecr/editorIN";
import {SiteConditionSund,} from "../../elevator/sundryDj/editor";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config记录, tail设备} from "./FormatOriginal";
import {RecheckEditor} from "../../common/editor";
import {DeviceSurveyD} from "../../crane/editor";
import {MeasureJudgmentMem, } from "../../amusement/editor";
import {Ladder} from "../../tower/craneJj/Ladder";
import {WitnessErect} from "./WitnessErect";
import {Thickness} from "./Thickness";
import {MagneticLeak} from "../erecting/MagneticLeak";
import {MonitoringSys} from "../erecting/MonitoringSys";

// ,"pr":"※","ses":6  "r":3,"s":1,  ## "s":9非自拆分的同一个项目编号有多行小项目 , "vx":1 "bs":[9],"ss":[9],"ts":[9],"fs":[1]
const defFrameM={
    'CmnTowerCrane': `{ "mg":2, "dcl":"C","cl":"C",
       "sk":[{"no":"5", "r":4,"s":1 ,"bs":[3,4], "vx":1}
     ]}`,
};
export const default见证=[{ti:'起重机械选型和基础验收证明'},{ti:'起重机械试验载荷证明'}];
export const tItems现场=[
    ['1、动力源、环境温度、海拔高度、风速',{f:'T',
        N: <Text>1、试验的动力源、环境温度、海拔高度、风速符合标准和设计要求。</Text>},],
    ['2、不得有易燃、易爆以及腐蚀性',{f:'y',
        N: <Text>2、检验现场不得有易燃、易爆以及腐蚀性气体。</Text>},],
];
export const tail几何= <Text css={{"@media print": {fontSize: '0.75rem'}}}>
    注：1、以设计图样要求作为检验结果判定依据。<br/>
    2、有多个起升机构的，其余机构的起升高度测量值和结果填在备注栏中。<br/>
    3、未测量或无需测量的，仅填检验结果栏。
</Text>;


const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} children={tail设备} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('Conclusion', <ItemConclusion startd  label={'四、结论(下结论)'} nxtstyp={'检验'}/>),
    createItem('Witness', <WitnessErect label={'五、技术资料和工作见证材料 六、备注'} titles={['五','六']} defWitn={default见证}/>),
    createItem('Measure', <MeasureJudgmentMem config={config观测数据}  mem='观测备注'  label={'附录1 观测值及测量结果记录表'}>
                                {tail观测}
                            </MeasureJudgmentMem>),
    createItem('Thickness', <Thickness label={'附录2：C3.7.3 主要受力结构件断面有效厚度观测值及测量结果记录'}/>),
    createItem('Ladder', <Ladder config={config梯子} label={'附录3：C3.7.4 梯子、走台和栏杆观测值及测量结果记录表'}/>),
    createItem('Monitoring', <MonitoringSys label={'附录4：C4.2.2.5和C4.9.7安全监控管理系统参数验证表'}/>),
    createItem('MagneticLeak', <MagneticLeak label={'附录5：C4.9.8.1漏磁检查记录表'}/>),

    createItem('SiteCondition', <SiteConditionSund config={tItems现场} label={'附录6：现场检验条件确认'}/>),
    createItem('ReCheck', <RecheckEditor label={'附录7 检验不合格项目内容'} setup={setupItemAreaRoute}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='CmnTowerCrane'
                                             frameMod={defFrameM} />));


export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const recordPrintListNow =React.useMemo(() => {
      // config记录[2].l=witnessNos;     //动态的 工作见证 列表注入：
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config记录} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
